package com.android.examplelist;


import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class ParallaxViewPagerActivity extends FragmentActivity {

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.parallax);
		
		ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
		
	    ParallaxViewPager parallaxViewPager = (ParallaxViewPager) findViewById(R.id.container);
	    parallaxViewPager.setBackgroundResource(R.drawable.bg);
	    PageAdapter adapter = new PageAdapter(getSupportFragmentManager());
	    parallaxViewPager.setAdapter(adapter);

	}
	
	
	public static class PlaceholderFragment extends Fragment {

		private static final String EXTRA_POSITION = "EXTRA_POSITION";
		private static final int[] COLORS = new int[] { 0xFF33B5E5, 0xFFAA66CC, 0xFF99CC00, 0xFFFFBB33, 0xFFFF4444 };

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			final int position = getArguments().getInt(EXTRA_POSITION);
			final TextView textViewPosition = (TextView) inflater.inflate(R.layout.fragment_main, container, false);
			textViewPosition.setText(Integer.toString(position)+"x");
			textViewPosition.setTextColor(0xff000000);
			//textViewPosition.setBackgroundColor(COLORS[position - 1]);

			return textViewPosition;
		}

	}

	private static final class PageAdapter extends FragmentStatePagerAdapter {

		
		public PageAdapter(android.support.v4.app.FragmentManager fragmentManager) {
			super(fragmentManager);
		}


		@Override
		public Fragment getItem(int position) {
			final Bundle bundle = new Bundle();
			bundle.putInt(PlaceholderFragment.EXTRA_POSITION, position + 1);

			final PlaceholderFragment fragment = new PlaceholderFragment();
			fragment.setArguments(bundle);

			return fragment;
		}

		@Override
		public int getCount() {
			return 5;
		}

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case android.R.id.home:
				finish();
				return true;
			case R.id.action_settings:
				return true;
		}
		
		return super.onOptionsItemSelected(item);
	 }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
